08. Travel Times

Travel Times

Start Quiz:

Solution:

INSTRUCTOR NOTE:

Code

The gist for the code.

*This is optional code available for you if you'd like to try running it in Android Studio. Unsure what to do? Go to the "Experimenting with the Code" page. *

Note Have you noticed that when you try to display a number that has decimals, an integer number is displayed instead? This is because of the data type you are using, namely int. The rule when you try to display a decimal number as an int is that the decimal portion of the number will be truncated, meaning it is simply removed.

Example: display(3/2); will show 1. The 0.5 of 1.5 is removed.

If you want to use decimal values, you need to use a float or double datatype. These data types and more are listed here.